//
//  TestImagesTableVM.m
//  Cooper_Table_Example
//
//  Created by 计海峰 on 2021/7/27.
//  Copyright © 2021 jhfappkf@163.com. All rights reserved.
//

#import "TestImagesTableVM.h"

@interface TestImagesTableVM ()

@property (nonatomic, strong) NSMutableArray *imageArrays;

@property (nonatomic, assign) NSInteger index;

@end

@implementation TestImagesTableVM

- (void)initDown {
    self.index = 0;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        removeNavTabVCs(@[@"TestTableVM"], nil);
    });
}

- (void)forRows {
    NSMutableArray *sections = [NSMutableArray array];
    
    
    NSMutableArray *tmpRows = [NSMutableArray array];
  
    
    for (int i = 0; i < 5; i++) {
        RowImageBaseM *base = [RowImageBaseM defaultControl:[self imageControl:[self.imageArrays safeObjectAtIndex:self.index+i]]];
        base.bgVMarging = UIEdgeInsetsMake(0, 8, 0, 8);
        
        Row *row = [self genRowClassStr:@"TestSingleImageCell" model:base];
        [tmpRows addObject:row];
    }
    
    [sections addObject:[Section sectionWithRows:tmpRows]];
    
    [self.sections addObjectsFromArray:sections];
    
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.12 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        self.index+=5;
//        if (self.index + 5 > self.imageArrays.count) {
//            return;
//        }
//        [self forRows];
//    });
    
}

- (ImageControlM *)imageControl:(NSString *)url {
    ImageControlM *controlIMG = [ImageControlM defaultIMGUrl:url];
    controlIMG.vRadius = 4;
    controlIMG.vMasksToBounds = true;
    controlIMG.vTopCons = 4;
    controlIMG.vLeftCons = 4;
    controlIMG.vBottomCons = 4;
    controlIMG.imagePlaceholder = @"icon_notice";
//    controlIMG.vMaxHeightCons = (kScreen_Width - 16) * 0.6;
    controlIMG.vMaxWidthCons = (kScreen_Width - 16);
//    controlIMG.vWidthCons = 128.0;
//    controlIMG.vHeightCons = 88.0;
    controlIMG.containerWidthCons = kScreen_Width - 16;
    controlIMG.isScale = true;
    return controlIMG;
}

- (NSMutableArray *)imageArrays {
    if (!_imageArrays) {
        _imageArrays = [NSMutableArray array];
        for (int i = 236; i < 521; i++) {
            [_imageArrays addObject:[NSString stringWithFormat:@"https://dss1.bdstatic.com/kvoZeXSm1A5BphGlnYG/skin_zoom/%d.jpg", i]];
        }
    }
    return _imageArrays;
}

@end
